﻿Imports System
Imports System.IO
Imports System.Data.OleDb
Imports System.Data
Imports System.Drawing
Imports System.Drawing.Imaging
Namespace Arwani
    Partial Class Backend_AddEditRaffleListMaster
        Inherits System.Web.UI.Page

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If (Session("ADMIN_USER") IsNot Nothing) Then
                If Page.IsPostBack Then Exit Sub
                If Request.QueryString("id") <> "0" Then
                    Call getPromoById(Request.QueryString("id").ToString())
                End If
            Else
                Response.Redirect("Default.aspx")
            End If

        End Sub

        Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
            Dim strQ As String
            'Dim strQckh As String
            Dim arwCon As New ArwaniController

            'If ChkActive.Checked Then
            '    strQckh = "update RaffleMaster set Active=0"
            '    arwCon.ExecuteNonQuery(strQckh)
            'End If

            strQ = "update RaffleMaster set Name='" & txtName.Text & "', StartDate='" & calStartDate.SelectedDate & "', EndDate='" & calEndDate.SelectedDate & "',Description='" & txtDesc.Text & "',Message='" & txtMessage.Text & "' where id=" & Val(Request.QueryString("id"))
            arwCon.ExecuteNonQuery(strQ)
            Response.Redirect("RaffleListMaster.aspx")


        End Sub


        Public Sub getPromoById(ByVal Id As String)
            Dim arwCon As New ArwaniController
            Dim strQ As String = "select * from RaffleMaster where id=" & Id
            Dim dtTable As DataTable = arwCon.ExecuteQuery(strQ)
            If dtTable.Rows.Count > 0 Then
                If Not IsDBNull(dtTable.Rows(0)("Name")) Then Me.txtName.Text = dtTable.Rows(0)("Name")
                If Not IsDBNull(dtTable.Rows(0)("StartDate")) Then Me.TextBox1.Text = (Convert.ToDateTime(dtTable.Rows(0)("StartDate"))).Date
                If Not IsDBNull(dtTable.Rows(0)("EndDate")) Then Me.TextBox2.Text = (Convert.ToDateTime(dtTable.Rows(0)("EndDate"))).Date
                If Not IsDBNull(dtTable.Rows(0)("Description")) Then Me.txtDesc.Text = dtTable.Rows(0)("Description")
                If Not IsDBNull(dtTable.Rows(0)("Message")) Then Me.txtMessage.Text = dtTable.Rows(0)("Message")


                If Not IsDBNull(dtTable.Rows(0)("StartDate")) Then Me.calStartDate.SelectedDate = (Convert.ToDateTime(dtTable.Rows(0)("StartDate"))).Date
                If Not IsDBNull(dtTable.Rows(0)("EndDate")) Then Me.calEndDate.SelectedDate = (Convert.ToDateTime(dtTable.Rows(0)("EndDate"))).Date

                Me.calStartDate.VisibleDate = (Convert.ToDateTime(dtTable.Rows(0)("StartDate"))).Date
                Me.calEndDate.VisibleDate = (Convert.ToDateTime(dtTable.Rows(0)("EndDate"))).Date

                If Not IsDBNull(dtTable.Rows(0)("Active")) Then Me.ChkActive.Checked = Convert.ToBoolean(dtTable.Rows(0)("Active"))



            End If
        End Sub

        Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
            Response.Redirect("RaffleListMaster.aspx")
        End Sub

        Protected Sub calStartDate_SelectionChanged(sender As Object, e As System.EventArgs) Handles calStartDate.SelectionChanged
            TextBox1.Text = calStartDate.SelectedDate
        End Sub

        Protected Sub calEndDate_SelectionChanged(sender As Object, e As System.EventArgs) Handles calEndDate.SelectionChanged
            TextBox2.Text = calEndDate.SelectedDate
        End Sub
    End Class
End Namespace